Skip to content

fix(indexer): honor nested .gitignore files - #204

Merged
PatrickSys merged 1 commit into
masterfrom
fix/l15-bug-20261204
Dec 4, 2026
Merged

PatrickSys merged 1 commit into
masterfrom
fix/l15-bug-20261204

Conversation

@PatrickSys

Copy link
Copy Markdown
Owner

What changed

The indexer read .gitignore only at the project root, so files ignored by packages could appear in the preview and the saved index. The shared file scan now applies each nested .gitignore relative to its directory, including negations and excluded parent directories.

Reproduce

Create packages/api/generated.ts and put /generated.ts in packages/api/.gitignore. Run codebase-context reindex --no-embeddings from the project root. Before this fix, packages/api/generated.ts appears in the index. The regression test checks both the preview and the saved index.

Tests

  • Both new regression tests failed on master before the fix. The focused run passed 14 of 14 tests with the fix.
  • pnpm test on Windows with Node 24 passed 1,572 tests, skipped 2, and failed 0 across 167 test files.
  • Build, lint, formatting, and type checks passed.

Apply package ignore rules during the shared preview and index scan. Keep directory-relative matching and parent exclusions, and cover both index paths with regression tests.

Reuse: extend src/core/indexer.ts
Agent-Harness: codex
Agent-Session: 01a24044-09a7-7a31-91fc-c3e6a0977878
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T09:28:19.388075Z 790784f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 3/5RetriggerView in Greptile

[Medium impact] The change affects which files project previews and indexes include.

Restore support for linked root .gitignore files before merging.

Findings

  1. P1 Security Linked ignore rules disappear ▶

Summary

The shared scan now reads nested .gitignore files and applies their rules relative to each directory.

  • The indexer applies ignore rules from nested folders as it scans files.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Shared file scan] --> B[Load parent ignore rules]
  B --> C{Directory already ignored?}
  C -->|Yes| D[Keep inherited rules]
  C -->|No| E[Read local .gitignore]
  E --> F[Scope and append local rules]
  D --> G[Check source file]
  F --> G
  G --> H[Preview or saved index]
Loading

Reviews (1) · Last reviewed commit: "fix(indexer): honor nested .gitignore fi..." · Reviewed by Greptile

Comment thread src/utils/gitignore.ts
if (isRoot || !inherited?.ignores(`${directory}/`)) {
try {
const ignoreFile = path.join(rootPath, directory, '.gitignore');
if ((await fs.lstat(ignoreFile)).isFile()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Linked ignore rules disappear

If the root .gitignore is a readable symlink, lstat(...).isFile() returns false and none of its rules are loaded. Previously, scanFiles read the file directly and followed the link. A workspace linking to shared rules containing secrets.ts will now include that source file in the preview and saved index despite respectGitignore: true. Preserve the previous root behavior and add a regression test.

How this was verified: The new file-type check skips linked ignore files, and the shared scan accepts supported source files when the matcher returns false.

@PatrickSys
PatrickSys merged commit d32efb1 into master Dec 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant